﻿@using ZBJF.Warranty.Common.Enums.InsuranceWarranty
@using ZBJF.Warranty.WebProvider
@using ZBJF.Warranty.Common.Enums
@{
    ViewBag.Title = "Index";
}
@section Header{
    @Scripts.Render("~/bundles/datatable")
    @Styles.Render("~/Content/datatable")
}
@model ZBJF.Warranty.Model.InsuranceWarrantyRecord
<ul class="nav nav-tabs">
    <li class="active">
        <a href="/InsuranceWarrantyRecord/InsuranceWarrantyRecord?InsuranceWarrantyRecordTaskType=@Request["InsuranceWarrantyRecordTaskType"]">
            @(ZBJF.Warranty.Common.Common.EnumHelper.Instance.GetDescription(typeof(InsuranceWarrantyRecordTaskType), @Request["InsuranceWarrantyRecordTaskType"]))
        </a>
    </li>
    @*<li class="Add-R" @(Request["InsuranceWarrantyRecordTaskType"] == "10" ? "" : "style=display:none;")><a href="Javascript:;" id="exportExcel">导出已处理任务</a></li>
        <li class="Add-R" style="display:none;"><a href="Javascript:;" id="GetFiles" onclick="getFile()">获取文件</a></li>*@
</ul>
@using (Html.BeginForm("ExportInsuranceWarrantyRecordList", "InsuranceWarrantyRecord", FormMethod.Post, new { id = "excelForm" }))
{
    @Html.Hidden("InsuranceWarrantyRecordTaskType", Request["InsuranceWarrantyRecordTaskType"])
    <table>
        <tr>
            <td>报案单号：</td>
            <td>
                @Html.TextBoxFor(m => m.WarrantyRecordNo, new { @class = "input-small" })
            </td>
            <td>报案人：</td>
            <td>@Html.TextBoxFor(m => m.Reporter, new { maxlength = 20, @class = "input-small" })</td>
            <td>报案人电话：</td>
            <td>@Html.TextBoxFor(m => m.ReporterPhone, new { maxlength = 20, @class = "input-small" })</td>
            <td>工单状态：</td>
            <td>
                @{
                    byte pageType = Convert.ToByte(Request["InsuranceWarrantyRecordTaskType"]);
                    byte parentStatus = 0;
                    if (pageType == (byte)InsuranceWarrantyRecordTaskType.ToBeProcess)
                    {
                        parentStatus = (byte)InsuranceWarrantyStatus.Processing;
                    }
                    else
                    {
                        parentStatus = (byte)InsuranceWarrantyStatus.Processed;
                    }
                }

                @Html.DropDownListFor(c => c.Status, ConvertToSelector.Instance.InsuranceWarrantyRecordConvertToSelectList(pageType))
            </td>
        </tr>
        <tr>
            <td>第三方保单号：</td>
            <td>
                @Html.TextBox("ThirdOrderNO", "", new { @class = "input-small" })
            </td>
            <td>被保险人：</td>
            <td>@Html.TextBox("UserName", "", new { maxlength = 15, @class = "input-small" })</td>
            <td>被保险人电话：</td>
            <td>@Html.TextBox("UserPhone", "", new { maxlength = 15, @class = "input-small" })</td>
            <td>证件号码：</td>
            <td>@Html.TextBox("CertificateNO", "", new { maxlength = 20, @class = "input-medium" })</td>
        </tr>
        <tr>
            <td>第三方承保公司：</td>
            <td>@Html.TextBox("InsuranceCompany", "", new { maxlength = 20, @class = "input-small", onmousemove = "this.title=this.value" })</td>
            <td>承保公司分公司：</td>
            <td>@Html.TextBox("InsuranceCompanyBranch", "", new { maxlength = 20, @class = "input-small", onmousemove = "this.title=this.value" })</td>

            <td>保险报案日期：</td>
            <td>
                @Html.TextBox("CreateTimeStart", "", new { @class = "Wdate input-small", onclick = "WdatePicker()" })
                @Html.TextBox("CreateTimeEnd", "", new { @class = "Wdate input-small", onclick = "WdatePicker()" })
            </td>
            <td>设备识别码：</td>
            <td>@Html.TextBox("IMEI", "", new { maxlength = 20, @class = "input-medium" })</td>
        </tr>
        <tr>
            <td>保险产品类型：</td>
            <td>
                <select id="InsuranceCategoryName" name="InsuranceCategoryName">
                    <option value="">请选择</option>
                    <option value="碎屏险">碎屏险</option>
                </select>
            </td>
            <td>保险产品名称：</td>
            <td>
                @Html.TextBox("ProductName", "", new { maxlength = 20, @class = "input-small" })
            </td>
            <td>保险日期：</td>
            <td>
                @Html.TextBox("ServiceStartTime", "", new { @class = "Wdate input-small", onclick = "WdatePicker()" })
                @Html.TextBox("ServiceEndTime", "", new { @class = "Wdate input-small", onclick = "WdatePicker()" })
            </td>
            <td>销售商户：</td>
            <td>@Html.TextBox("SaleVendorName", "", new { maxlength = 20, @class = "input-small" })</td>
        </tr>
        <tr>
            <td>跟进客服：</td>
            <td>@Html.DropDownList("SystemServiceUserId", ConvertToSelector.Instance.SystemUserToSelectList())</td>
            <!--已处理任务才有这个查询条件-->
            @if (Request["InsuranceWarrantyRecordTaskType"] == ((int)InsuranceWarrantyRecordTaskType.Processed).ToString())
            {
                <td>关单日期：</td>
                <td>
                    @Html.TextBox("CloseOrderTimeStart", "", new { @class = "Wdate input-small", onclick = "WdatePicker()" })
                    @Html.TextBox("CloseOrderTimeEnd", "", new { @class = "Wdate input-small", onclick = "WdatePicker()" })
                </td>
            }
            <td colspan="2">
                <input id="btnSubmit" class="btn btn-primary Search-R margin-l-10" type="button" value="查询" onclick="search();" />
                <input id="btnSubmit" class="btn btn-primary Search-R margin-l-10" type="button" value="重置" onclick="reset();search();" />
                <!--已处理任务-->
                @if (Request["InsuranceWarrantyRecordTaskType"] == ((int)InsuranceWarrantyRecordTaskType.Processed).ToString())
                {
                    <input id="exportExcel" class="btn btn-success margin-l-10" type="button" value="导出已处理任务" />
                    <a id="GetFiles" onclick="getFile()" class="btn btn-primary Search-R margin-l-10" style="display:none;">获取文件</a>
                }
                else if (Request["InsuranceWarrantyRecordTaskType"] == ((int)InsuranceWarrantyRecordTaskType.ToBeProcess).ToString())
                {
                    <input id="btnStayExport" class="btn btn-success Search-R margin-l-10" type="submit" value="导出待处理任务" />
                }

            </td>
        </tr>
    </table>
                    }
<div class="table-responsive dataTables_wrapper">
    <table id="insuranceWarrantyRecordList" class="table table-striped table-bordered table-hover">
        <thead>
            <tr>
                <th width="20">序号</th>
                <th width="100">报案单号</th>
                <th width="100">报案人</th>
                <th width="100">报案人电话</th>
                <th width="100">保险产品类别</th>
                <th width="100">保险产品名称</th>
                <th width="100">第三方承保公司</th>
                <th width="100">承保公司分公司</th>
                <th width="100">销售商户</th>
                <th width="100">创建时间</th>
                <th width="80">跟进人</th>
                <th width="120">总耗时</th>
                <th width="80">工单状态</th>
                <th width="80">最后编辑时间</th>
                <th width="100">操作</th>
            </tr>
        </thead>
    </table>
</div>
@section scripts{
<script src="~/Content/js/moment.js"></script>
    <script type="text/javascript">
        window.onload = function() {
            search();
        }
        function reset() {
            document.getElementById("excelForm").reset();
        }
        var isSearch = false;
        var zipFileName = '';
        $(function() {
            var objTable = $("#insuranceWarrantyRecordList")
                .dataTable({
                    fnDrawCallback: function() {
                        ControlPermissionOperate();
                    },
                    "aaSorting": [[9, "desc"]],
                    "sAjaxSource": "/InsuranceWarrantyRecord/InsuranceWarrantyRecord?InsuranceWarrantyRecordTaskType=@Request["InsuranceWarrantyRecordTaskType"]",
                    //bSort:false,
                    aoColumns: [
                        {
                            "mData": null,
                            "bSortable": false,
                            "fnRender": function(nRow) {
                                return nRow.iDataRow + 1;
                            }
                        },
                        { "mData": "WarrantyRecordNo", "bSortable": true },
                        { "mData": "Reporter","bSortable": false  },
                        { "mData": "ReporterPhone" ,"bSortable": false },
                        { "mData": "InsuranceCategoryName" ,"bSortable": false },
                        { "mData": "ProductName","bSortable": false  },
                        { "mData": "InsuranceCompany","bSortable": false  },
                        { "mData": "InsuranceCompanyBranch" ,"bSortable": false },
                        { "mData": "SaleVendorName","bSortable": false  },
                        { "mData": "CreateTime"  },
                        { "mData": "ServiceName" ,"bSortable": false },
                        { "mData": "CostTotalSecond","bSortable": false },
                        { "mData": "StatusDesc" ,"mDataProp":"Status" },
                        { "mData": "LastModifyTime"  },
                        { "mData": null,"bSortable": false }
                    ],
                    "fnRowCallback": function(nRow, aData, iDisplayIndex) {
                        var html = "";
                        switch("@(Request["InsuranceWarrantyRecordTaskType"])")
                        {
                            case "@((byte) InsuranceWarrantyRecordTaskType.ToBeProcess)":
                                html= "<a class='Edit-R' href='/InsuranceWarrantyRecord/Processing/" + aData.ID + "' title='处理任务'>处理任务</i></a>";
                                break;
                            case "@((byte) InsuranceWarrantyRecordTaskType.ToBeReturnVisit)":
                                html = "<a class='Edit-R' href='/InsuranceWarrantyRecord/Processing?id=" + aData.ID + "&IsToVisit=true' title='详情'>详情</i></a>";
                                break;
                            default :
                                html = "<a class='Edit-R' href='/InsuranceWarrantyRecord/Processing/" + aData.ID + "' title='详情'>详情</i></a>";

                        }
                        //if ("(Request["InsuranceWarrantyRecordTaskType"])" == "((byte) InsuranceWarrantyRecordTaskType.ToBeProcess)") {
                        //    html = "<a class='Edit-R' href='/InsuranceWarrantyRecord/Processing/" + aData.ID + "' title='处理任务'>处理任务</i></a>";
                       // } else if ("(Request["InsuranceWarrantyRecordTaskType"])" == "((byte) InsuranceWarrantyRecordTaskType.Processed)") {
                       //     html = "<a class='Edit-R' href='/InsuranceWarrantyRecord/Processing/" + aData.ID + "' title='详情'>详情</i></a>";
                        //} else if ("(Request["InsuranceWarrantyRecordTaskType"])" == "((byte) InsuranceWarrantyRecordTaskType.ToBeReturnVisit)") {
                        //    html = "<a class='Edit-R' href='/InsuranceWarrantyRecord/Processing?id=" + aData.ID + "&IsToVisit=true' title='详情'>详情</i></a>";
                       // } else if ("(Request["InsuranceWarrantyRecordTaskType"])" == "((byte) InsuranceWarrantyRecordTaskType.ReturnVisited)") {
                        //    html = "<a class='Edit-R' href='/InsuranceWarrantyRecord/Processing/" + aData.ID + "' title='详情'>详情</i></a>";
                       // }
                        $('td:eq(14)', nRow).html(html);
                    }
                });
        });

        function search() {
            queryParamList.WarrantyRecordNo = $("#WarrantyRecordNo").val();
            queryParamList.Reporter = $("#Reporter").val();
            queryParamList.ReporterPhone = $("#ReporterPhone").val();
            queryParamList.Status = $("#Status").val();
            queryParamList.ThirdOrderNO = $("#ThirdOrderNO").val().trim();
            queryParamList.UserPhone = $("#UserPhone").val();
            queryParamList.UserName = $("#UserName").val();
            queryParamList.CertificateNO = $("#CertificateNO").val();
            queryParamList.ServiceStartTime = $("#ServiceStartTime").val();
            queryParamList.ServiceEndTime = $("#ServiceEndTime").val();
            queryParamList.IMEI = $("#IMEI").val();
            queryParamList.InsuranceCategoryName = $("#InsuranceCategoryName").val();
            queryParamList.ProductName = $("#ProductName").val();
            queryParamList.SaleVendorName = $("#SaleVendorName").val();
            queryParamList.InsuranceCompany = $("#InsuranceCompany").val();
            queryParamList.InsuranceCompanyBranch = $("#InsuranceCompanyBranch").val();
            queryParamList.SystemServiceUserId = $("#SystemServiceUserId").val();
            queryParamList.CreateTimeStart = $("#CreateTimeStart").val();
            queryParamList.CreateTimeEnd = $("#CreateTimeEnd").val();
            queryParamList.CloseOrderTimeStart = $("#CloseOrderTimeStart").val();
            queryParamList.CloseOrderTimeEnd = $("#CloseOrderTimeEnd").val();
            $("#insuranceWarrantyRecordList").dataTable().fnDraw();
        }

        function getFile() {
            layer.confirm('确定要获取各项任务的附件资料吗？',{
                btn:['确认', '取消']
            },function(_index){
                layer.close(_index);
                $.ajax({
                    url: '@Url.Action("DownloadFiles")',
                    dataType: "json",
                    type: "POST",
                    data: { content: "/UploadFile/File/zipOrder/" + zipFileName + ".zip" },
                    async: false,
                    success: function(data) {
                        re = data.sucess;
                        if (data.sucess)
                        {
                            //$("#GetFiles").attr("href", "/UploadFile/File/zipOrder/" + zipFileName + ".zip").attr("onclick", "").trigger("click");
                            window.location.href = "/UploadFile/File/zipOrder/" + zipFileName + ".zip"
                        }
                        else {
                            layer.alert(data.message)
                        }
                    }
                });
            },function(_index){
                layer.close(_index);
            });

        }

        $(function() {
            //导出excel
            $("#exportExcel").on("click", function() {
                layer.confirm('确定要导出已处理任务清单吗？', {
                    btn: ['确认', '取消']
                }, function(index, layero){
                    zipFileName = Date.parse(new Date());
                    layer.confirm('是否需要同步导出各项任务的附件资料？',{
                        btn:['是','否']
                    },function(_index){
                        layer.close(_index);
                        exportFile(queryParamList,zipFileName,true)
                    },function(_index){
                        layer.close(_index);
                        exportFile(queryParamList,zipFileName,false)
                    });


                }, function(index){
                });
            });
        });

        function exportFile(_queryParamList,_zipFileName,_isNeedLoadFile){
            $("#GetFiles").attr("href", "javascript:;").attr("onclick", "getFile()");
            search();
            queryParamList.InsuranceWarrantyRecordTaskType = @Request["InsuranceWarrantyRecordTaskType"];
            window.location.href = '@Url.Action("ExportInsuranceWarrantyRecord")?content=' + JSON.stringify(_queryParamList) + "&zipFileName=" + _zipFileName+"&isNeedLoadFile="+_isNeedLoadFile;
            if(_isNeedLoadFile)
                $("#GetFiles").show();
        }
    </script>
}

